package com.admin.education.models;

import com.admin.education.repositories.Identifiable;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;

@Entity
@Table(name = "role")
@EntityListeners(AuditingEntityListener.class)
@Data
public class Role implements Serializable, Identifiable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    @Column(name="role_name")
    @Length(max = 32)
    @NotBlank
    @NotNull
    private String roleName;
    @Column(name = "role_description")
    @Length(max = 32)
    private String roleDescription;
    @Column(name = "is_valid")
    @NotNull
    private  boolean isValid;
    @NotNull
    @Column(name="admin_manage")
    private  boolean adminManage;
    @OneToMany(fetch = FetchType.LAZY,mappedBy = "roles")
    @JSONField(serialize=false)
    private List<UserInformation> userInformations;
    @ManyToMany
    @JSONField(serialize=false)
    private List<Menus> menus;
    @ManyToMany
    @JSONField(serialize=false)
    private List<Scopes> scopes;
    @OneToMany(mappedBy = "role")
    @JSONField(serialize = false)
    private List<ApplyCrowd> applyCrowds;
}
